﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using TMDT_Nhom1A.DTO;
using System.Collections;

namespace TMDT_Nhom1A.DAO
{
    public class ChildCatalogue_DAO
    {
        private static QL_DoanhNghiepDataContext qldoanhnghiep = new QL_DoanhNghiepDataContext();

        public static List<CHILD_CATALOGUE> ListCatalogue(int parentcatalogue)
        {
            List<CHILD_CATALOGUE> listcatalogue = new List<CHILD_CATALOGUE>();
            var list =
                    from pc in qldoanhnghiep.PARENT_CATALOGUEs
                    join cc in qldoanhnghiep.CHILD_CATALOGUEs
                            on pc.ParentCatalogue_ID equals cc.ParentCatalogue_ID
                    where pc.ParentCatalogue_ID == parentcatalogue
                    select new { cc.ChildCatalogue_ID, cc.ChildCatalogue_Name, pc.ParentCatalogue_ID };
            foreach (var item in list)
            {
                CHILD_CATALOGUE catalogue = new CHILD_CATALOGUE();
                catalogue.ChildCatalogue_ID = item.ChildCatalogue_ID;
                catalogue.ChildCatalogue_Name = item.ChildCatalogue_Name;
                catalogue.ParentCatalogue_ID = item.ParentCatalogue_ID;
                listcatalogue.Add(catalogue);
            }
            return listcatalogue;
        }

        
    }
}
